package com.calefk.core {
	
	import com.calefk.util.Collection;
	import com.calefk.util.Iterator;

	public class List extends Collection {
		
		public function List() {
			super();
		}
		
		public function update(dt:int):void {
			// aqui no utilizo iterator 
			// con el objetivo de optimizar la rapidez del loop
			// ya que se ejecuta por cada update
			if (mData == null) { return; }
			var len:int = mData.length;
			for (var k:int = 0; k < len; k++) {
				var obj:ClassBase = mData[k];
				if (obj.toClean) {
					obj.clean();
					mData.splice(k, 1);
					len--;
					k--;
				} else {
					obj.update(dt);
				}
			}
		}
		
		public function cleanElement(obj:ClassBase):void {
			obj.clean();
			removeElement(obj);
		}
		
		public function cleanElements():void {
			var it:Iterator = iterator();
			while (it.hasNext()) {
				var item:ClassBase = it.next();
				item.clean();
				it.remove();
			}
		}
		
		public function clean():void {
			var it:Iterator = iterator();
			while (it.hasNext()) {
				var item:ClassBase = it.next();
				item.clean();
				it.remove();
			}
			mData = null;
		}
	}

}